// 缩放工具函数
export const useScale = () => {
  // 基础设计尺寸
  const BASE_WIDTH = 2560
  const BASE_HEIGHT = 1080

  // 获取当前缩放比例
  const getScaleRatio = () => {
    const windowWidth = window.innerWidth
    const windowHeight = window.innerHeight
    const scaleX = windowWidth / BASE_WIDTH
    const scaleY = windowHeight / BASE_HEIGHT
    return Math.min(scaleX, scaleY)
  }

  // 将设计稿尺寸转换为实际尺寸
  const scaleSize = (size) => {
    const ratio = getScaleRatio()
    return size * ratio
  }

  // 将设计稿位置转换为实际位置
  const scalePosition = (x, y) => {
    const ratio = getScaleRatio()
    return {
      x: x * ratio,
      y: y * ratio,
    }
  }

  // 创建响应式的缩放样式
  const createScaleStyle = (baseStyle) => {
    const ratio = getScaleRatio()
    return {
      ...baseStyle,
      transform: `scale(${ratio})`,
      transformOrigin: 'top left',
    }
  }

  return {
    getScaleRatio,
    scaleSize,
    scalePosition,
    createScaleStyle,
    BASE_WIDTH,
    BASE_HEIGHT,
  }
}

// 全局缩放状态管理
export const scaleState = {
  isAdaptive: true,
  scaleRatio: 1,
}

// 设置缩放状态
export const setScaleState = (isAdaptive, scaleRatio = 1) => {
  scaleState.isAdaptive = isAdaptive
  scaleState.scaleRatio = scaleRatio
}
